<template>
  <div>
    <div class="node" style="height: 300px">
      <!-- <el-tabs v-model="tab_id" type="border-card">
        <el-tab-pane v-for="item in fields" :key="item.id" :label="item.title" :name="item.id"> -->
          <div style="padding:20px;min-height:300px">
            <xdh-form :model="model" :fields="fields" @submit="handleSubmit">
            </xdh-form>
          </div>
        <!-- </el-tab-pane>
      </el-tabs> -->

    </div>
  </div>
</template>
<style lang="stylus" rel="stylesheet/stylus" scoped type="text/stylus">
.node {
  position: relative;
  font-size: 16px;
  padding: 5px;
  padding-top: 10px;

  &::before {
    content: '';
    display: block;
    overflow: hidden;
    height: 0;
    width: 1px;
  }
}
</style>
<script type="text/ecmascript-6">
import XdhForm from '@/widgets/xdh-form'
import FormMixin from '@/base/mixin/forms'
import cloneDeep from 'lodash/cloneDeep'
import Vue from 'vue'
import { getForms } from '@/widgets/helper/storage'

export default {
  name: 'Prenode',
  components: {
    XdhForm
  },
  mixins: [FormMixin],
  props: {
    scope: {
      type: Object
    },
    stacked: {
      type: Boolean,
      default: true
    },
    info: {
      required: true,
      type: Array
    },
    tabs: {
      required: true,
      type: Array
    },
    slotStyle: {
      type: Object,
      default: null
    }
  },
  data: function () {
    return {
      oldId: '',
      tab_id: '0',
      isActive: false,
      currPage: '',
      oldStyle: {},
      nodeInfo: (() => {
        if (this.scope) {
          return cloneDeep(this.info)
        } else {
          return this.info
        }
      })(),
      slots: this.info.hasSlot ? (i) => `slot${i}` : false,
      config: {},
      fields: [],
      load: null
    }
  },
  computed: {
    model() {
      const m = {}
      this.fields[this.tab_id]['content'].forEach(item => {
        if (!item) return
        // 分隔线组件无值
        if (item.type !== 'divider') {
          m[item.prop] = (item.props || {}).value || item.value
        }
      })
      return m
    }
  },
  watch: {
    info: {
      deep: true,
      handler: function (newVal) {
        var info = {}
        if (this.scope) {
          info = cloneDeep(newVal)
        } else {
          info = newVal
        }
        this.nodeInfo = info
      }
    },
  },
  created() {
    this.fields = this.info || []
  },
  mounted() {

  },
  methods: {
    clone(data) {
      console.log('clone')
      return JSON.parse(JSON.stringify(data))
    },
    handleSubmit(model) {
      console.log('submit', model, this.fields)
      this.$message({
        message: '若要保存页面，请点击头部的保存按钮1',
        type: 'success'
      });

    },
    cloneDeep: cloneDeep,
  }
}
</script>

